/*
 * @Descripttion: 
 * @version: 
 * @Author: ada.wu
 * @Date: 2023-11-20 23:40:19
 * @LastEditors: ada.wu
 * @LastEditTime: 2023-11-21 23:52:22
 */

import { ref } from 'vue';
import { defineStore } from 'pinia';
import EsAjax from '@/utils/EsAjax';
import ApiUrls from '@/apis/index';

/**
 * 
 */
export default defineStore('room', () => {
  // 权限代码数据
  const roomList = ref([]);
  const roomAllList = ref([]);
  function getRoomList(id) {
    roomList.value = []
    EsAjax.post(ApiUrls.roomList, { id: id }).then(res => {
      if (res.data.data && res.data.data.length) {
        // res.data.data.forEach(element => {
        //   element.name = element.floor
        // });
        roomList.value = res.data.data || [];
      }
    }).catch(err => {
      ElMessage.error(err.message);
    })
  }
  function getRoomAllList() {
    roomAllList.value = []
    EsAjax.post(ApiUrls.roomAll, { }).then(res => {
      if (res.data.data && res.data.data.length) {
        // res.data.data.forEach(element => {
        //   element.name = element.floor
        // });
        roomAllList.value = res.data.data || [];
      }
    }).catch(err => {
      ElMessage.error(err.message);
    })
  }

  return {
    roomAllList,
    roomList,
    getRoomList,
    getRoomAllList,
  }
}) 